<template>
  <div style="margin: 100px 100px 400px 400px">

    <el-card style="width: 500px;height: 400px;">

      <el-form ref="form" :model="form" :rules="rules" label-width="70px">

        <el-form-item label="用户名" prop="userName">

          <el-input v-model="user.userName" disabled></el-input>

        </el-form-item>

        <el-form-item label="学/工号" prop="userId">

          <el-input v-model="user.userId" disabled></el-input>

        </el-form-item>

        <el-form-item label="修改密码" prop="professionName">

          <el-input v-model="form.password1" placeholder="请输入密码"></el-input>

          <el-input v-model="form.newPassword" placeholder="请确认密码"></el-input>

        </el-form-item>

      </el-form>

      <div style="text-align: center">

        <el-button icon="el-icon-success" type="success" @click="saveProfession(user.roleId,user.userId)">确 定

        </el-button>

      </div>

    </el-card>


  </div>
</template>

<script>
import request from '@/utils/request';
export default {
  name: "PersonalCenter",
  data() {
    return {
      user: JSON.parse(localStorage.getItem("user")),
      form: {
        password1: '',
        newPassword: ''
      }
    }
  },
  methods: {
    saveProfession(roleId, userId) {
      console.log(userId)
      if (roleId == '1') {
        request.put("/login/changestudentpassword/" + userId + "/" + this.form.newPassword).then(response => {
          if (response) {
            {
              this.$message({
                showClose: true,
                message: '恭喜你，修改成功哦~',
                type: 'success'
              });
              this.$router.push('/home')
            }
          }
        })
      } else if (roleId == '2') {
        request.put("/login/changeteacherpassword/" + userId + "/" + this.form.newPassword).then(response => {
          if (response) {
            {
              this.$message({
                showClose: true,
                message: '恭喜你，修改成功哦~',
                type: 'success'
              });
              this.$router.push('/home')
            }
          }
        })
      } else if (roleId == '3') {
        request.put("/login/changeadminpassword/" + userId + "/" + this.form.newPassword).then(response => {
          if (response) {
            {
              this.$message({
                showClose: true,
                message: '恭喜你，修改成功哦~',
                type: 'success'
              });
              this.$router.push('/home')
            }
          }
        })
      }

    }
  }
}
</script>

<style scoped>

</style>
